<template>
  <div v-loading.fullscreen="fullscreenLoading">
    <template>
      <el-row class="margin-top">
        <el-col :span="12">
          <div>
            <el-button
              type="text"
              v-for="(item, k) in excelFileInfos"
              :key="k"
              @click="batchReportWaybillData(item.id, item.fileName)"
            >
              导出{{ item.fileName }}
            </el-button>
          </div>
          <!-- <div
            v-for="(item, k) in excelFileInfos"
            :key="k"
            @click="batchReportWaybillData(item.id, item.fileName)"
          >
            导出{{ item.fileName }}
          </div> -->
        </el-col>
      </el-row>
    </template>
  </div>
</template>

<script>
import { ajax, actionPermission } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { m } from "@/store/yg/common/local";

export default {
  data() {
    return {
      fullscreenLoading: false,
      excelFileInfos: [],
      shippingWay: ""
    };
  },
  props: ["row", "data", "more"],
  mounted() {
    this.intitExcelFileInfos();
  },
  methods: {
    batchReportWaybillData(excelFileId, fileName) {
      var param = {};
      const ids = this.$store.state.edit.ids;
      param["param4"] = excelFileId;
      param["ids"] = ids;
      console.info("param", param);
      this.fullscreenLoading = true;
      ajax("batchReportWaybillData", param).then(
        res => {
          this.fullscreenLoading = false;
          console.log(res);
          if (res.code == 200) {
            var path = (path = constant.FILE_SERVER + res.data);
            if (res.data) {
              fileName = res.data.substring(
                res.data.lastIndexOf("/") + 1,
                res.data.length
              );
            }

            window.open(
              constant.API_SERVER +
                "/open/downloadFileByHttp?fileName=" +
                fileName +
                "&path=" +
                path
            );

            // console.log(fileUrl);
            // window.open(fileUrl);
          } else {
            if (null != res.message) {
              this.$message.error("导出失败原因：" + res.message);
            } else {
              this.$message.error("导出失败");
            }
          }
        },
        error => {
          this.fullscreenLoading = false;
          console.log(error);
        }
      );
    },

    // 初始化 下载
    intitExcelFileInfos() {
      var param = {};
      //获取当前路由地址
      const urlPath = this.$route.path;
      if (urlPath.indexOf("waybill__seafreightlist__list") >= 0) {
        param["code"] = "Y";
        //console.info('这是海运');
        param["shippingWayType"] = "FCL";
      } else if (urlPath.indexOf("waybill__airfreightlist__list") >= 0) {
        param["code"] = "Y";
        //console.info('这是空运');
        param["shippingWayType"] = "AIR";
      } else if (urlPath.indexOf("waybill__expressdelivery__list") >= 0) {
        param["code"] = "Y";
        //console.info('这是待审批');
        param["shippingWayType"] = "99";
      } else if (urlPath.indexOf("waybill__seafreightmerge__list") >= 0) {
        param["code"] = "M";
        param["shippingWayType"] = "FCL";
      } else if (urlPath.indexOf("waybill__airfreightmerge__list") >= 0) {
        param["code"] = "M";
        param["shippingWayType"] = "AIR";
      }

      ajax("intitExcelFileInfos", param).then(
        res => {
          if (res.code == 200) {
            this.excelFileInfos = res.data;
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    permission(commit) {
      return actionPermission(
        this.displayRules,
        commit,
        this.data,
        this.$store.state
      );
      return true;
    }
  }
};
</script>

<style lang="scss" scoped>
.menu-list {
  min-width: 12vw;
  max-height: 90vh;
  overflow-y: auto;
  div {
    padding: 6px 8px;
    cursor: pointer;
    font-size: 12px;
    &:hover {
      background: #51abd1;
      color: #fff;
    }
  }
}
.letter {
  letter-spacing: -2px;
}
.icon-border {
  display: inline-block;
  border: 1px solid;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
}
</style>
